#!/bin/sh
workcount=1

function look30sec() {
	sleep 6
	for i in $(seq 1 5) ;do
		adb -s ${adbclient}:5555 shell input swipe $xstart $ystart $xstart $(expr $ystart - 390) 2000
		sleep 7
	done
}

function botting() {
	echo $worklist | sed "s/ /\n/g" > /tmp/worklist${sectionname}.adbtmp
	workline=$(cat /tmp/worklist${sectionname}.adbtmp)
	for m in $workline;do
		if [ "$m" == "skip" ];then
			screensize=$(adb -s ${adbclient}:5555 shell wm size | cut -d ':' -f 2 | sed -e "s/ //g;s/\n//g;s/\r//g")
			if [ ${screensize} == "1080x1920" ];then
				basey=$(expr $basey + $(uci get adbrun.@adbinit[0].diantaoskip))
			elif [ ${screensize} == "720x1280" ];then
				basey=$(expr $basey + $(uci get adbrun.@adbinit[0].diantaoskip) \* 2 / 3)
			elif [ ${screensize} == "800x1280" ];then
				basey=$(expr $basey + $(uci get adbrun.@adbinit[0].diantaoskip) \* 3 / 4)
			fi
		else
			result=$(echo $m | grep "秒")
			if [ "$result" != "" ];then
				adbtimes=$(echo $m | sed "s/秒/\n/;s/次//" | tail -n 1)
				switchtimes=$(echo $m | sed "s/秒/\n/" | head -n 1)
				switchtimes=$(expr $switchtimes \* 1)
				adbswitchtimes=$(expr $switchtimes / 30)
				ltimes=0
				while [ $ltimes -lt $adbtimes ]
				do
					adb -s ${adbclient}:5555 shell input tap $basex $basey
					sleep 3
					for i in $(seq 1 $adbswitchtimes) ;do
						look30sec
					done
					adb -s ${adbclient}:5555 shell input keyevent 4
					sleep 6
					ltimes=$(expr $ltimes + 1)
				done
			else
				adbtimes=$(echo $m | sed "s/分钟/\n/;s/次//" | tail -n 1)
				switchtimes=$(echo $m | sed "s/分钟/\n/" | head -n 1)
				switchtimes=$(expr $switchtimes \* 60)
				adbswitchtimes=$(expr $switchtimes / 30)
				ltimes=0
				while [ $ltimes -lt $adbtimes ]
				do
					adb -s ${adbclient}:5555 shell input tap $basex $basey
					sleep 3
					for i in $(seq 1 $adbswitchtimes) ;do
						look30sec
					done
					adb -s ${adbclient}:5555 shell input keyevent 4
					sleep 6
					ltimes=$(expr $ltimes + 1)
				done
			fi
		fi
		workcount=$(expr $workcount + 1)
	done
}

